package com.wwwarehouse.financialcenter.fragment.moneywarehouse.bankcard;


import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.financialcenter.R;
import com.wwwarehouse.financialcenter.bean.bindingcard.BankInfoBean;
import com.wwwarehouse.financialcenter.constant.FinancialConstant;
import com.wwwarehouse.financialcenter.fragment.base.MyBaseViewPagerFragment;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description:
 * Copyright  : Copyright (c) 2017
 * Author     : yfwang
 * Date       : 2017/11/14 20:11
 */
public class AddBankBranchFragment extends MyBaseViewPagerFragment {

    @Override
    public void setTitle() {
        if (peekFragment() instanceof AddBankBranchFragment)
            mActivity.setTitle(getString(R.string.financial_center_add_bank));
    }

    @Override
    protected void init(View view) {
        super.init(view);
        Bundle bundle = getArguments();
        if (bundle != null) {
            String bankUkid = bundle.getString("bankUkid");
            String province = bundle.getString("province");
            String city = bundle.getString("city");
            Map<String, Object> map = new HashMap<>();
            map.put("bankUkid", bankUkid);
            map.put("provinceName", province);
            map.put("cityName", city);
            httpPost(FinancialConstant.GETSBANKINFO, map, 0, true, "");
        }


    }

    @Override
    public void onSuccess(CommonClass commonClass, int what) {
        if (what == 0) {
            if (TextUtils.equals("0", commonClass.getCode())) {
                List<BankInfoBean.DataBean> dataBeen = JSON.parseArray(commonClass.getData().toString(), BankInfoBean.DataBean.class);
                if (dataBeen != null) {
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("data", (Serializable) dataBeen);
                    SetFragmentAndPage(dataBeen.size(), 8, new BankBranchListFragment().getClass().getName(), bundle);
                }

            } else {
                toast(commonClass.getMsg());
            }
        }
    }
}
